package com.itheima.controller;

import com.itheima.common.CompanyResult;
import com.itheima.common.Result;
import com.itheima.common.SubjectResult;
import com.itheima.pojo.hm.HmSubjectsDirectorys;
import com.itheima.pojo.hm.HmSubjectsTags;
import com.itheima.service.DirectorysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
 *@Parm
 *@ClassName DirectorysController
 *@Date 2022/1/10 15:01
 */
@RestController
@RequestMapping("/directorys")
public class DirectorysController {
    @Autowired
    private DirectorysService directorysService;

    @PutMapping("/{id}")
    public CompanyResult updateById(@PathVariable Integer id, @RequestBody HmSubjectsDirectorys directorys){
        return directorysService.updateById(directorys);
    }

    @GetMapping
    public Result findPage(Integer page, Integer pagesize, String directoryName, Integer state, Integer subjectID){
        return directorysService.findPage(page,pagesize,directoryName,state,subjectID);
    }

    @DeleteMapping("/{id}")
    public CompanyResult deleteById(@PathVariable Integer id,@RequestBody HmSubjectsDirectorys directorys){
        return directorysService.deleteById(id);
    }

    @PostMapping
    public CompanyResult addDirectory(@RequestBody HmSubjectsDirectorys directorys){
        return directorysService.add(directorys);
    }

    @PostMapping("/{id}/{state}")
    public CompanyResult updateByState(@PathVariable Integer id,@PathVariable Integer state){
        return directorysService.updateByState(id,state);
    }

    @GetMapping("/{id}")
    public HmSubjectsDirectorys findOne(@PathVariable Integer id){
        return directorysService.findOne(id);
    }

    @GetMapping("/simple")
    public List<SubjectResult> SimpleDirectory(Integer subjectID){
        List<SubjectResult> resultList  = directorysService.SimpleDirectory(subjectID);
        return resultList;
    }
}
